This tutorial is a walkthrough building a TensorFlow CNN model

Import the required libraries, this step might take some time

Loading a dataset from the tensorflow_datasets module

Since we need some data to train a predictive model on, we can leverage the tensorflow_datasets module and load some of its preprocessed datasets with a few lines of code; specifically, we will be loading the Fashion MNIST dataset from the tensorflow_datasets module.

Here is a breakdown and an explanation for the parameters that we have to set while using the tensorflow_datasets API:

Preprocessing the data

The 28 x 28 pixels images have their pixel values ranging from 0 to 255, we will need to normalize these values to be ranging from 0 to 1, this will help the training to be faster and more stable

Split the training data into train and validation datasets

Building and training the model

Time to build our a CNN TensorFlow model, I will leverage the high level Keras API as it makes life much easier.

As we can see, the number of the Trainable parameters in the CNN model are much more than the Vanilla NN. However, the model will require much less epochs to train compared to the Vanilla NN.

Once the model's architecture is defined, we need to comile the model. During this step we will need to define a:

After defining the model's architecture and combiling the model, it's time to train the model. Training is the process in which the model learns the pattern mapping the inputs to the outputs. To train the model, we use the .fit() method. The parameters defined below are:

Evaluating the model

Once the model completes the training process, it's time to evaluate the model and its predictions. The Keras model object has a history attribute which can be used to load information about the model performance during training

Evaluating the model's performance over the test set

We can see the model has achieved around 92% accuracy after training for just 10 epochs compared to the 89% accuracy achieved by the Vanilla NN after training for 50 epochs.

We can see the model is still not performing well with some of the shirt examples, so let's visualize some of them.